package com.whfc.ms.api.sys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whfc.common.result.PageData;
import com.whfc.common.util.PageUtil;
import com.whfc.emp.dto.AppEmpDTO;
import com.whfc.emp.entity.FileUploadInfo;
import com.whfc.emp.service.AppEmpService;
import com.whfc.emp.service.FileUploadInfoService;
import com.whfc.entity.dto.Apply.rep.EntryApplicationListRep;
import com.whfc.entity.dto.Apply.rep.FileUploadInfoRep;
import com.whfc.entity.dto.Apply.rep.QueryEmpSysIdDto;
import com.whfc.entity.dto.Apply.req.AppEntryApplicationReq;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.fuum.service.SysUserService;
import com.whfc.ms.api.sys.service.SysFileUploadService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
@Service
public class SysFileUploaServiceImpl implements SysFileUploadService {


    @DubboReference(interfaceClass = FileUploadInfoService.class, version = "1.0.0", timeout = 30000)
    private FileUploadInfoService fileUploadInfoService;
    @DubboReference(interfaceClass = SysUserService.class, version = "1.0.0")
    private SysUserService sysUserService;
    @DubboReference(interfaceClass = AppEmpService.class, version = "1.0.0")
    private AppEmpService appEmpService;
    @Override
    public List<FileUploadInfoRep> getAllWxFileList(AppEntryApplicationReq req) {
        List<FileUploadInfoRep> allFileList = fileUploadInfoService.selectFileUrlByMeetingId(req.getId());
        for (FileUploadInfoRep info : allFileList) {
            List<QueryEmpSysIdDto> appEmpIds = sysUserService.getAppEmpEmpNamesIdList(Arrays.asList(info.getUserName()));
            for (QueryEmpSysIdDto queryEmpSysId : appEmpIds) {
                AppEmpDTO empInfo = appEmpService.getEmpInfo(queryEmpSysId.getAppEmpId());
                info.setUserName(empInfo.getEmpName());
            }
        }
        return allFileList;

    }

    @Override
    public Integer uploadWxFile(SysUser user, FileUploadInfo fileInfo) {
        fileInfo.setUserId(user.getId());
        int rows = fileUploadInfoService.uploadFile(fileInfo);
        return rows > 0 ? fileInfo.getId() : -1;
    }

    @Override
    public String getWxFileUrlById(Integer fileId) {
        if (fileId == null) {
            return null;
        }
        return fileUploadInfoService.getFileUrlById(fileId);
    }
}
